package bairui.international.console.web.controller.barter.category.properties;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.types.Predicate;

import bairui.international.model.domain.jpa.TB_ProductCategoryProperty;
import bairui.international.service.Service_ProductCategoryProperty;

/**
 *
 * 属性详情
 *
 * @generated
 * 
 * @see STest_C_Barter_Category_PropertiesDetail_Page 测试
 *
 */
@Controller
public class C_Barter_Category_PropertiesDetail_Page
 extends SC_Barter_Category_PropertiesDetail_Page 
{
	
	@Autowired private Service_ProductCategoryProperty service_ProductCategoryProperty;
	
	/**
	 * 分页列表
	 */
	@SuppressWarnings("serial")
	@Action(Page.class)
	@GetMapping(value=Page.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object page(
		HttpServletRequest request, 
		@PathVariable(name=Page.PathVariableName.CategoryId) long categoryId
	) throws Exception {
		org.springframework.data.domain.Page<TB_ProductCategoryProperty> page = service_ProductCategoryProperty.page(
				it->Page.Filter.query(it, request, new Page.Filter.FilterExtends() {
					@Override public Predicate gainName(String name) {
						return it.productProperty.name.like("%" + name + "%");
					}
				})
				.and(it.productCategory.id.eq(categoryId)), 
				Page.Output.page(request), 
				it->Page.Output.sort(it, request, new Page.Output.OrderExtends() {
					@Override public Sort gainName(Direction direction) {
						return sort(direction, it.productProperty.name);
					}
					@Override public Sort gainComment(Direction direction) {
						return sort(direction, it.productProperty.comment);
					}
				})
			);
		//
		return Page.Output.output(
				page
					.map(it->new Page.Output.Model(it){
							@Override protected void assign_before() {
							}
							@Override public String assignName() {
								return it.getProductProperty().getName();
							}
							@Override public String assignComment() {
								return it.getProductProperty().getComment();
							}
						}
					)
			);
	}
	

}
